﻿using AIStudio.Wpf.Demo01.Models;
using AIStudio.Wpf.Demo03.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace AIStudio.Wpf.Demo01.Controls
{
    public class DiagramCanvas : Canvas
    {
        protected override void OnDragOver(DragEventArgs e)
        {
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
           

            base.OnDragOver(e);
        }

        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);          

            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
            if (dragObject != null)
            {
                Point position = e.GetPosition(this);

                MainWindowViewModel mainViewModel = this.DataContext as MainWindowViewModel;
                var lineBase = Activator.CreateInstance(dragObject.SharpBase.GetType()) as SharpBase;
                lineBase.Left = position.X;
                lineBase.Top = position.Y;
                lineBase.Width = 100;
                lineBase.Height = 100;
                mainViewModel.Items.Add(lineBase);
            }
           
            e.Handled = true;

            this.Focus();
        }
    }
}
